Conversation
|
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here with What to do if you already signed the CLAIndividual signers
Corporate signers
ℹ️ Googlers: Go here for more info. |
|
CLAs look good, thanks! ℹ️ Googlers: Go here for more info. |
|
@matthieuxyz thanks for the detailed explanation! I implemented this fix for the |
|
Seems good to me. I made a pull request with additional tests to make sure: |
Why:
Fix a random UnicodeDecodeError, when using AdbCommands.Logcat.
Steps to reproduce
Expected result
Output result as unicode string (or str in python3)
Actual result
UnicodeDecodeError is sometime raised with the following message:
The exception is raised from the method AdbMessage.StreamingCommand() from the module adb_protocol.py:
Investigation
When streaming output of command, a max length is provided to UsbHandle.BulkRead. This length is (if I understood correctly) given in bytes.
So the end of a bulk of bytes data can append at any given bytes.
But in utf-8, characters may be encoded on multiples bytes (ex: あ (U+3042) is encoded as 0xE3 0x81 0x82 in utf-8).
Since, the bulk may end at any given bytes, it is possible for a multi-byte sequence to be split between two bulks (ex: [b'...\xe3', b'\x81\x82...'] ).
But, decoding will fail if a multi-byte sequence is incomplete (try to run
b'AAA\xe3'.decode('utf-8')in a python console).What:
This pull request contains...
A test case with a
@skipdecorator to illustrate the problem.New "Bytes" methods that implements a "workaround" (ie. using bytes and decode only when stream is complete)
New tests to cover the new "Bytes" methods
There is probably a better solution, but this is what worked for me. And I hope that it will help to illustrate the problem with StreamingCommand.